package com.question.view.command;

import com.question.entity.User;
import com.question.service.ISeedtimeService;
import com.question.service.impl.SeedtimeServiceImpl;
import com.question.utils.InputOutUtils;
import com.question.view.Application;

public class LoginCommand implements INoLoginCommand{
	private ISeedtimeService seedtimeService = new SeedtimeServiceImpl();
	@Override
	/*
	 * 用户登录
	 */
	public void exec() {
		while(true) {
			InputOutUtils.print("******登陆******");
			String username = InputOutUtils.inputString("用户名:", false);
			String password = InputOutUtils.inputString("密码:", false);
			User user = new User(username, password);
			User reUser = seedtimeService.login(user);
			if(reUser !=null) {
				Application.setUser(reUser);
				InputOutUtils.print(reUser.getDisplay_name()+"欢迎回来");
				break;
			}else {
				InputOutUtils.print("用户名或密码错误");
				if(InputOutUtils.inputString("是否重试[YorN]:", false).equalsIgnoreCase("N"))break;
			}
		}
	}

}
